﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Login
{
    public class Constants
    {
        public const string USER_NAME = "TenDangNhap";
        public const string PASSWORD = "MatKhau";
        
    }

    public class SessionManager : System.Web.UI.Page
    {
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            SessionManager.CheckSession(Context);
        }

        public static void CheckSession(HttpContext context)
        {
            string userName = "";
            context.Session.Timeout = 5;
            if (context.Session[Constants.USER_NAME] != null)
            {
                userName = context.Session[Constants.USER_NAME].ToString();
            }

            if (userName == "")
            {
                DoLogin();
            }

        }

        public static string GetUserName(HttpContext context)
        {
            string ret = "";
            if (context.Session[Constants.USER_NAME] != null)
            {
                ret = context.Session[Constants.USER_NAME].ToString();
            }

            return ret;
        }

        public static string GetPassword(HttpContext context)
        {
            string ret = "";
            if (context.Session[Constants.PASSWORD] != null)
            {
                ret = context.Session[Constants.PASSWORD].ToString();
            }

            return ret;
        }



        private static void DoLogin()
        {
            //Todo
            // Response.Redirect("Login.aspx");
        }
    }
}
